package com.mxnet.chongjin.nci.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.mxnet.chongjin.nci.R;
import com.mxnet.chongjin.nci.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

public class IndexActivity extends BaseActivity implements View.OnClickListener {
    private Context mContext;
    private TextView mTextView;
    private Button mButton1, mButton2, mButton3, mButton4, mButton5, mButton6, mButton7, mButton8, mButton9;
    private SharedPreferences mPreferences;
    private SharedPreferences.Editor mEditor;
    private List<String> mStringList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        mContext = IndexActivity.this;

        mPreferences = getSharedPreferences("nci", MODE_PRIVATE);
        mEditor = mPreferences.edit();

        mTextView = findViewById(R.id.textview_index);
        mTextView.setText(mPreferences.getString("username", ""));

        mButton1 = findViewById(R.id.btn_index1);
        mButton1.setOnClickListener(this);

        mButton2 = findViewById(R.id.btn_index2);
        mButton2.setOnClickListener(this);

        mButton3 = findViewById(R.id.btn_index3);
        mButton3.setOnClickListener(this);

        mButton4 = findViewById(R.id.btn_index4);
        mButton4.setOnClickListener(this);

        mButton5 = findViewById(R.id.btn_index5);
        mButton5.setOnClickListener(this);

        mButton6 = findViewById(R.id.btn_index6);
        mButton6.setOnClickListener(this);

        mButton7 = findViewById(R.id.btn_index7);
        mButton7.setOnClickListener(this);

        mButton8 = findViewById(R.id.btn_index8);
        mButton8.setOnClickListener(this);

        mButton9 = findViewById(R.id.btn_index9);
        mButton9.setOnClickListener(this);

        mStringList = new ArrayList<>();
        mStringList.add("02766270");
        mStringList.add("02768475");
        mStringList.add("02769903");
        mStringList.add("02776154");
        mStringList.add("02774528");
        mStringList.add("00493796");
        mStringList.add("00493797");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_index1:
                // 检验入库
                Intent intent1 = new Intent(mContext, InspectionActivity.class);
                startActivity(intent1);
//                OkHttpUtils.get()
//                        .url("http://ncihz.mxnet.cn/test")
//                        .addParams("list", new Gson().toJson(mStringList))
//                        .build()
//                        .execute(new StringCallback() {
//                            @Override
//                            public void onError(Call call, Exception e, int id) {
//                                Log.i("*****onError", e.getMessage());
//                            }
//
//                            @Override
//                            public void onResponse(String response, int id) {
//                                Log.i("*****onResponse", response);
//                            }
//                        });
                break;
            case R.id.btn_index2:
                // 入库前查询
                Intent intent2 = new Intent(mContext, PreInspectionListActivity.class);
                startActivity(intent2);
                break;
            case R.id.btn_index3:
                // 入库核对
                Intent intent3 = new Intent(mContext, StockCheckActivity.class);
                startActivity(intent3);
                break;
            case R.id.btn_index4:
                // 入库管理
                Intent intent4 = new Intent(mContext, ManageInInventoryActivity.class);
                startActivity(intent4);
                break;
            case R.id.btn_index5:
                // 移库
                Intent intent5 = new Intent(mContext, ManageMoveInventoryActivity.class);
                startActivity(intent5);
                break;
            case R.id.btn_index6:
                // 出库管理
                Intent intent6 = new Intent(mContext, ManageOutInventoryActivity.class);
                startActivity(intent6);
                break;
            case R.id.btn_index7:
                // 盘点管理
                Intent intent7 = new Intent(mContext, ManageInventoryActivity.class);
                startActivity(intent7);
                break;
            case R.id.btn_index8:
                // 修改密码
                Intent intent8 = new Intent(mContext, ChangePasswordActivity.class);
                startActivity(intent8);
                break;
            case R.id.btn_index9:
                //退出
                boolean mac = mPreferences.getBoolean("isGetMac", false);
                String deviceNo = mPreferences.getString("deviceNo", "");
                String urlHeader = mPreferences.getString("URL_HEADER", "");
                mEditor.clear();
                mEditor.putString("deviceNo", deviceNo);
                mEditor.putBoolean("isGetMac", mac);
                mEditor.putString("URL_HEADER", urlHeader);
                mEditor.commit();
                Intent intent9 = new Intent(mContext, LoginActivity.class);
                startActivity(intent9);
                finish();
                break;
        }
    }
}
